# 数据文件迷你化
import os
import pandas as pd

if __name__ == '__main__':
    folder_path = 'instacart_market/'
    folder_path_mini = 'instacart_market_mini/'
    files = [f for f in os.listdir(folder_path) if f.endswith('.csv')]
    for file in files:
        file_path = os.path.join(folder_path, file)
        # 使用pandas读取文件的前1000行
        data = pd.read_csv(file_path, nrows=1000)

        # 将新的文件名设为原文件名加上'_new'后缀
        new_file = file.split('.')[0] + '.csv'
        new_file_path = os.path.join(folder_path_mini, new_file)

        # 将数据写入新的文件
        data.to_csv(new_file_path, index=False)

        # 打印文件名称
        print(file)


